<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *      [PinTuXiu] (C)2001-2099 ONightjar.com Pintuxiu.com.
 *      This is NOT a freeware, use is subject to license terms
 */

class misc_api{
	public function parse_at($message,$type='share'){
		if($this->permission['other_permission']['allow_at_friend']) {
			$atlist = $atlist_tmp = array();
			preg_match_all("/@([^\r\n]*?)\s/i", $message.' ', $atlist_tmp);
			$atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, 3);
	
			if(!empty($atlist_tmp)) {
				$ptx_user = spClass('ptx_user');
				$ptx_message = spClass('ptx_message');
				foreach($ptx_user->find_userid_by_uname($atlist_tmp) as $row) {
					$atlist[$row['user_id']] = $row['nickname'];
					$ptx_message->add_at($this->current_user['user_id'],$row['user_id'],$type);
				}
			}
	
			if($atlist) {
				foreach($atlist as $atuid => $atusername) {
					$atsearch[] = "/@$atusername /i";
					$atreplace[] = "[at=$atuid]@{$atusername}[/at] ";
					$atsearch_str .= "atuser$atuid ";
				}
				$message = preg_replace($atsearch, $atreplace, $message.' ', 1);
			}
		}
		return array('message'=>$message,'atsearch_str'=>$atsearch_str);
	}
	
	public function parse_tag($message){
		$taglist = $taglist_tmp = array();
		$message = parse_plain_message($message);
		preg_match_all("/#([^\r\n]*?)#/i", $message.' ', $taglist_tmp);
		$taglist_tmp = array_slice(array_unique($taglist_tmp[1]), 0, 6);
		$taglist_tmp = implode($taglist_tmp, ' ');
		return $taglist_tmp;
	}
}